import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { TagService } from './tag.service';
import { CreateTagDto } from './dto/create-tag.dto';
import { UpdateTagDto } from './dto/update-tag.dto';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiParam,
  ApiQuery,
  ApiBody,
  ApiCreatedResponse,
  ApiOkResponse,
  ApiNotFoundResponse,
} from '@nestjs/swagger';
import { Public } from '../common/isPublic';
@ApiTags('文章标签')
@Controller('tag')
@Public()
export class TagController {
  constructor(private readonly tagService: TagService) {}

  @Post()
  @ApiOperation({ summary: '创建一个新的标签' })
  @ApiBody({ type: CreateTagDto })
  @ApiCreatedResponse({ description: '标签创建成功', type: CreateTagDto })
  create(@Body() createTagDto: CreateTagDto) {
    return this.tagService.create(createTagDto);
  }

  @Get()
  @ApiOperation({ summary: '获取所有标签' })
  @ApiOkResponse({ description: '标签列表获取成功', type: [CreateTagDto] })
  findAll() {
    return this.tagService.findAll();
  }

  @Get(':id')
  @ApiOperation({ summary: '根据ID获取单个标签' })
  @ApiParam({ name: 'id', description: '标签ID' })
  @ApiOkResponse({ description: '标签信息获取成功', type: CreateTagDto })
  @ApiNotFoundResponse({ description: '标签不存在' })
  findOne(@Param('id') id: string) {
    return this.tagService.findOne(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新一个标签' })
  @ApiParam({ name: 'id', description: '标签ID' })
  @ApiBody({ type: UpdateTagDto })
  @ApiOkResponse({ description: '标签更新成功', type: UpdateTagDto })
  update(@Param('id') id: string, @Body() updateTagDto: UpdateTagDto) {
    return this.tagService.update(id, updateTagDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除一个标签' })
  @ApiParam({ name: 'id', description: '标签ID' })
  @ApiOkResponse({ description: '标签删除成功' })
  @ApiNotFoundResponse({ description: '标签不存在' })
  remove(@Param('id') id: string) {
    return this.tagService.remove(id);
  }
}
